package com.csw.util;

import com.csw.pojo.Brand;
import com.csw.pojo.Cell;
import com.csw.pojo.Layer;
import com.csw.pojo.Map;

import java.awt.*;
import java.util.ArrayList;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2022/12/1 0:11
 */
public class MapUtil {

    public static Map built(Integer height)  {
        Map map = new Map();
        map.setHeight(height);

        //最上面一层
        Layer layer1 = LayerUtil.bulid(3, 3);
        Layer layer2 = LayerUtil.bulid(3, 3);
        //最下面一层
        Layer layer3 = LayerUtil.bulid(3, 3);
        //下一页
        layer3.setNextLayer(layer2);
        layer2.setNextLayer(layer1);
        layer1.setNextLayer(null);
        map.getLayerList().add(layer1);
        map.getLayerList().add(layer2);
        map.getLayerList().add(layer3);
        return map;
    }


    public static Boolean compare(Brand brand,Layer layer){
        Cell[][] cells = layer.getCells();
        for (int i = 0; i < cells.length; i++) {
            for (int j = 0; j < cells[i].length; j++) {
                Cell cell = cells[i][j];
                if (cell.getState()==1){
                    Brand nextBrand = cell.getBrand();
                    Rectangle nextBrandBounds = nextBrand.getBounds();
                    Rectangle bound = brand.getBounds();
                    boolean intersects = bound.intersects(nextBrandBounds);
                    if (intersects){
                        return true;
                    }
                }



            }
        }
        //该卡片下一层没判断到,递归判断下下层
        if (layer.getNextLayer()!=null){
           return compare(brand, layer.getNextLayer());
        }else {
            return false;
        }


    }

}
